<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                         |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: songaimin@clcw.com.cn  Blog:http://blog.csdn.net/samxx8        |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\System;

/**
* 来拍车APP设备操作类
* @author   sam 
*/
class AppDevice {
    
    /*
    * @param $info{
                  dev_uuid   //设备id
                  ,dev_uid   //用户id
                  ,dev_jpush_id  //极光推送平台id
                  }
    * @return null
    */
     public function save($info){

        if(empty($info['dev_uuid']) || empty($info['dev_uid']) || empty($info['dev_jpush_id']) )
            return false;

        $row = M('app_devices')->where('dev_jpush_id="'.$info['dev_jpush_id'].'" AND dev_uid="'.$info['dev_uid'].'" AND dev_uuid="'.$info['dev_uuid'].'"')->find();
        if($row){
            $ok =  M("app_devices")->where("dev_id=".$row['dev_id'])->save(array('dev_modifytime'=>date("Y-m-d H:i:s")));
            return $ok;
        }else{
            $info['dev_create_time'] = $info['dev_modifytime'] =  date('Y-m-d H:i:s');
            $info['user_type'] = C("ACCOUNT_TYPE");
            $info['dev_type'] = strlen($info['dev_uuid'])>15?2:1;
            $info['dev_user_type'] = 2;
            $ok = M('app_devices')->add($info);
            return $ok;
        }
    }

    /** 通过vin码查询用户jpushid
     * @param $vin
     * @return array
     
    public  static function get_jpush_by_repair($vin){
            $prefix = C('DB_PREFIX');
            $sql = "select  r.dealer_id as dealer_id,d.uid as uid ,c.contact_mobile as mobile from {$prefix}dealer_repair_log as r LEFT JOIN
                    {$prefix}car_dealer as c ON r.dealer_id=c.dealer_id
                    LEFT JOIN {$prefix}dealer_user as d on d.dealer_id=r.dealer_id
                    where r.vin='".$vin."' and search_state=1 ";

            $result = M()->query($sql);
            $new_result = array();
            foreach($result as $key=>$value){
                    $new_result['mobile']= $value['mobile'];
                    $state = M('app_devices')->field('dev_jpush_id')->where('dev_uid='.$value['uid'])->find();
                    $new_result['jpush_id'] = empty($state)?'':$state['dev_jpush_id'];
            }
        return $new_result;
    }
    */
}

?>
